﻿

//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {
        //获取提报人employeeId
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/GetCurrentUser.aspx", {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str != "-1") {
                        var token = str.split('_');
                        instance[0].EditWho = token[0];
                    }
                }
                catch (e) {
                }
                finally {

                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    });
    instance[0].EditDate = new Date();

    var fun = getPar1("fun");
    if (fun == "view") {
        parent.setButtonHiden();
        $("div input").attr("disabled", true).css("background", "whitesmoke");
        $("div select ").attr("disabled", true).css("background", "whitesmoke");
        setTimeout(HideButton, 200);
    }

//    $("#wkWorkTimeDetail").find("td").hover(function () {
//        var hang = $(this).parent().prevAll().length + 1;
//        var lie = $(this).prevAll().length + 1;
//        alert("第" + hang + "行，第" + lie + "列");
//    })

}

function HideButton() {
    $("#wkWorkTimeDetail thead:first-child").hide();
}

var fnCheckData = function () {
    try {
        if ($("#Name").val() == "") {
            return "班次名不能为空！";
        }

        var tempTime = $("#BeginTime").val() + ":01";
        if (!isTime(tempTime)) {
            return "开始时间格式不对!";
        }
        tempTime = $("#EndTime").val() + ":01";
        if (!isTime(tempTime)) {
            return "结束时间格式不对!";
        }
        var reg = /^\d+(\.\d+)?$/;       
        if (reg.test($("#TimeLength").val()) == false) {
            return "时长需要输入非零数字!";
        }
    }
    catch (e)
     { }
 }

 //计算班次时长
 var calcTimeLength = function (obj) {
     var row = getTableRow(obj);
     var beginTime = $("#BeginTime", row).val();
     var endTime = $("#EndTime", row).val();
     var begindate = "2012-09-21 ";
     var enddate = "2012-09-21 ";
     //如果班次结束时间小于开始时间，则应该算第二天的
     if (beginTime > endTime) {
         enddate = "2012-09-22 ";
     }
     //组装正确的日期时间，以备后续计算间隔
     beginTime = begindate + beginTime + ":00";
     endTime = enddate + endTime + ":00";
     $("#TimeLength", row).val(dateDiff("H", beginTime, endTime))
 }

 var calcTotalTimeLength = function (obj) {
     var beginTime = $("#Master input[name='BeginTime']").val();
     var endTime = $("#Master input[name='EndTime']").val();
     var begindate = "2012-09-21 ";
     var enddate = "2012-09-21 ";
     //如果班次结束时间小于开始时间，则应该算第二天的
     if (beginTime > endTime) {
         enddate = "2012-09-22 ";
     }
     //组装正确的日期时间，以备后续计算间隔
     beginTime = begindate + beginTime + ":00";
     endTime = enddate + endTime + ":00";
     $("#Master input[name='TimeLength']").val(dateDiff("H", beginTime, endTime))
 }
 













